package xjtu.se.articlecommunity.buser.login.dao;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import xjtu.se.articlecommunity.buser.login.dto.BLoginDto;


public interface BLoginDao {
    @Select("select count(u_id) from t_user where (u_id=#{u_key} or u_mail=#{u_key} or u_tel=#{u_key}) and u_passwd=#{password} and u_role=1")
    int findCountByID(BLoginDto dto);

    @Select("select count(*)  from t_user where u_mail = #{u_mail} " +
            "and u_role = 1")
    int checkMail(@Param("u_mail") String mail);

    @Select("select count(*) from t_user where u_tel = #{u_tel} " +
            "and u_role = 1")
    int checkTel(@Param("u_tel") String tel);

    @Select("select u_passwd from t_user where ${key}=#{value} and u_role = 1")
    String getPw(@Param("key") String key, @Param("value") String value);

    @Update("update t_user set u_role=3 where (u_id=#{u_key} or u_mail=#{u_key} or u_tel=#{u_key}) and u_passwd=#{password}")
    void applyforBuser(BLoginDto dto);
}
